<?php Yii::app()->clientScript->registerScriptFile(Helper::getUrl('js/jquery-1.4.3.min.js'))?>
<script type="text/javascript">
(function($){
	$(function(){
        var data = $('#post-form').serialize();
        setInterval(function(){
            var serialize = $('#post-form').serialize();
            if (data == serialize) return;
            data = serialize;
            $("#cache img").show();
            $.ajax({
                url:"<?php echo $this->createUrl('tempcache', array('id' => $model->id))?>",
                type:"post",
                data:data,
                dataType:'json',
                success:function(data){
                    $("#cache span").html("自动保存时间：" +data.time);
                    $("#cache img").hide();
                    $("#cache a").show();
                }
            });
        }, 5000);
        if ($("#cache span").html() == '') {$("#cache a").hide();}
	})
})(jQuery)

function cleanConfirm(){
    return confirm("确定要清除缓存吗？") ? true : false;
}
</script>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'post-form',
	'enableAjaxValidation'=>false,
)); ?>

<?php echo $form->errorSummary($model); ?>

<div class="row">
	<?php echo $form->labelEx($model,'cid'); ?>
	<?php echo $form->dropDownList($model, 'cid', CHtml::listData($model->categoryData->findAll(), 'id', 'name'))?>
	<?php echo $form->error($model,'cid'); ?>
    <div id="cache"><img src="<?php echo Helper::getUrl('images/loading.gif')?>">
    <span><?php if (!empty($time)) echo '上次自动保存时间：' . $time;?></span>
    <?php if($model->id):?>
    <?php echo CHtml::link('清除', array('update', 'id' => $model->id, 'ct' => 1), array('onclick' => 'return cleanConfirm()'))?>
    <?php else:?>
    <?php echo CHtml::link('清除', array('create', 'ct' => 1), array('onclick' => 'return cleanConfirm()'))?>
    <?php endif;?>
    </div>
</div>

<div class="row">
	<?php echo $form->textArea($model,'content_markdown',array('id' => 'elm1', 'style' => 'height:450px;width:100%')); ?>
	<?php echo $form->error($model,'content_markdown'); ?>
</div>

<div class="row">
	<?php echo $form->labelEx($model,'tag'); ?>
	<?php echo $form->textField($model,'tag',array('maxlength'=>64, 'style' => 'width:200px')); ?>
	<?php echo $form->error($model,'tag'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model, 'top')?>
    <?php echo $form->checkbox($model, 'top')?>
</div>

<div class="row buttons">
	<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->